﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace Ji.LilyControl
{

    public class DoubleClickHelper
    {

        /// <summary>
        ///  Helper.LilyControl.DoubleClickHelper.CreatHelper(this.maingrid).PreviewDoubleClick +=
        /// </summary>
        /// <param name="element"></param>
        /// <returns></returns>
        public static DoubleClickHelper CreatHelper(UIElement element)
        {
            return new DoubleClickHelper(element);
        }

        /// <summary>
        /// 双击事件  
        /// </summary>
        public event EventHandler<System.Windows.Input.MouseButtonEventArgs> PreviewDoubleClick;

        protected DoubleClickHelper(UIElement element)
        {
            element.PreviewMouseLeftButtonDown += element_PreviewMouseLeftButtonDown;
        }

        void element_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (e.ClickCount == 2)
            {
                OnDoubleClick(e);
            }
        }

        protected void OnDoubleClick(System.Windows.Input.MouseButtonEventArgs e)
        {
            if (this.PreviewDoubleClick != null)
            {
                this.PreviewDoubleClick(this, e);
            }
        }
    }
}
